package com.egao.ap.controller;

import com.egao.ap.entity.Information;
import com.egao.ap.entity.Settings;
import com.egao.ap.service.InformationService;
import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 * 帖子
 * @author : Doman
 * @date : 2020-10-12 14:21:51
 * @version ：1.0
 */

@Api(tags = "帖子")
@RestController
@RequestMapping("/api/nt/ap/information")
public class InformationNtController extends BaseController {

	@Autowired
	private InformationService informationService;

	/**
	 * 分页查询列表
	 */
    @ApiOperation("分页查询帖子")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, Information information) throws Exception{
        return informationService.list(page, information);
    }

    /**
     * 根据id查询帖子
     */
    @ApiOperation("根据id查询帖子")
    @PostMapping("/get")
    public JsonResult get(Information information) {
        return informationService.getById(information);
    }

    /**
     * 根据id查询帖子
     */
    @ApiOperation("根据id查询帖子")
    @PostMapping("/getSettings")
    public JsonResult getSettings(Settings settings) {
        return informationService.getByType(settings);
        // 使用关联查询
        //PageParam<information> pageParam = new PageParam<>();
        //pageParam.put("id", id);
        //List<information> records = informationService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    /**
     * 查询全部帖子
     */
    @ApiOperation("查询全部帖子")
    @PostMapping("/list")
    public JsonResult list(Information information){
        return informationService.list(information);
    }

    /**
     * 查询全部帖子
     */
    @ApiOperation("查询全部帖子")
    @PostMapping("/nkzxf")
    public JsonResult nkzxf(Information information){
        return informationService.appList(information);
    }


    /**
     * 添加帖子
     */
    @OperLog(value = "帖子", desc = "添加", param = false, result = true)
    @ApiOperation("添加帖子")
    @PostMapping("/save")
    public JsonResult save(Model model, Information information) {
        return informationService.save(information, getLoginUser());
    }

    /**
     * 修改帖子
     */
    @OperLog(value = "帖子", desc = "修改", param = false, result = true)
    @ApiOperation("修改帖子")
    @PostMapping("/update")
    public JsonResult update(Model model, Information information) {
        return informationService.update(information, getLoginUser());
    }

    /**
     * 删除帖子
     */
    @OperLog(value = "帖子", desc = "删除", result = true)
    @ApiOperation("删除帖子")
    @PostMapping("/remove")
    public JsonResult remove(Information information ) {
        return informationService.remove(information, getLoginUser());
    }

    /**
     * 批量添加帖子
     */
    /**@RequiresPermissions("ap:information:save")
    @OperLog(value = "帖子", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Information> list) {
        if (informationService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改帖子
     */
    /**@RequiresPermissions("ap:information:update")
    @OperLog(value = "帖子", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Information> batchParam) {
        if (batchParam.update(informationService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除帖子
     */
    /**@RequiresPermissions("ap:information:remove")
    @OperLog(value = "帖子", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (informationService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
